genVectorNegate
in genMath.lib
Vector Functions Function List by Category Alphabetical Function List
int genVectorNegate(
float *VectorA, // pointer to array holding
vector A
float *VectorB, // pointer to array for vector B
int dimen)
// dimension of vectors A and B
This function computes the negative of a vector of dimension n:
b(i) = -a(i)
The explicit routines VectorNegate2d and VectorNegate3d are faster due to code
optimizations in the explicit algorithms.
The
return code is errno, defined in the C standard library (math.h). This is
an integer value
for math errors.
Sample Application:
/////////// splgnVNg.c for genVectorNegate Library Function ////////// // // // // For this sample, 3-d vectors are used. The vector is // // stored in array a and the negative is returned in array b. // // // //////////////////////////////////////////////////////////////////////
//////////////////////////// INCLUDES ////////////////////////////////
#include "stdio.h"
#include "genMath.h"
////////////////////////////// MAIN //////////////////////////////////
void main()
{
//local declarations
//integers
int i; // dimension counter
int retcode; // return code for call to genVectorNegate
//floats
float a[3]; // vector A
float b[3]; // vector B
//character strings
char ch; //input string to exit
//intialize the A vectors
a[0] = (float)1.234;
a[1] = (float)-.678;
a[2] = (float)10.3;
//negate the vector
retcode = genVectorNegate(a,b,3);
//display the result
printf("%s", "Resultant Components: \n\n");
for(i=0;i<=2;++i){
printf("%s%d%s%f%s", "b[",i,"] = ", b[i],"\n");
}
printf("%s","\n");
//display closing message and wait for <enter> before exiting
printf("Press <Enter> to end");
scanf("%c", &ch);
} // End Main
//////////////////////// End splgnVNg.c ///////////////////////
The reader may verify that the vector (array) a is negated.
Output from the test program splgnVNg.c:
Resultant Components:
b[0] = -1.234000
b[1] = 0.678000
b[3] = -10.300000